import { _decorator, CCInteger, Component, Node } from 'cc';
import { Joystick } from './Joystick';
const { ccclass, property } = _decorator;

@ccclass('TestJoystick')
export class TestJoystick extends Component {
    @property(Joystick)
    joystickCom: Joystick = null

    @property(Node)
    tragetNode: Node = null

    @property(CCInteger)
    tragetMoveSpeed: number = 100

    start() {

    }

    update(deltaTime: number) {
        if (this.joystickCom.isMove()) {
            const addVec3 = this.joystickCom.getDirection().multiplyScalar(this.tragetMoveSpeed * deltaTime)
            console.log("add position", addVec3)
            this.tragetNode.setPosition(this.tragetNode.getPosition().add(addVec3))
        }
        
        this.tragetNode.angle = this.joystickCom.getAngle()
    }
}